//****************************************************************
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   MacropartInfoAction.java  $$
//* $$Revision:   1.0  $$
//* $$Author:   aponte  $$
//* $$Date:   Nov 26 2008 11:56:32  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.view.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import ar.com.ford.it.fullEconomics.exception.FullEconomicsException;
import ar.com.ford.it.fullEconomics.facade.FullEconomicsFacade;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas012VehicleVw;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesc02Coststvers;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp06Mix;
import ar.com.ford.it.fullEconomics.view.form.MacropartInfoForm;
import ar.com.ford.it.webengine.facade.FacadeProvider;
import ar.com.ford.it.webengine.struts.AbstractBaseAction;
import ar.com.ford.it.webengine.struts.FordActionMapping;
import ar.com.ford.it.webengine.websession.WebSession;

public class MacropartInfoAction extends AbstractBaseAction {

    /**
     * 
     */
    public ActionForward initPage(FordActionMapping mapping,
                                  ActionForm actionForm,
                                  HttpServletRequest request,
                                  HttpServletResponse response,
                                  WebSession webSession, ActionMessages msgs,
                                  ActionMessages warns, ActionMessages errorMsgs) {
        MacropartInfoForm form = (MacropartInfoForm) actionForm;
        FullEconomicsFacade facade = (FullEconomicsFacade) FacadeProvider
                .getFacade(request, FullEconomicsFacade.class);

        try {
            Teesc02Coststvers costStructureVersion = (Teesc02Coststvers) request
                    .getAttribute("costStructureVersion");
            Ncas012VehicleVw vehicleLine = (Ncas012VehicleVw) request
                    .getAttribute("vehicleLine");
            Teesp06Mix mix = (Teesp06Mix) request.getAttribute("mix");
            form.setCostStrVersion(costStructureVersion);
            form.setVehicleLine(vehicleLine);
            form.setMix(mix);
            form.setDetails();
            form.setMacropartStructCol(facade.buildMacropart(form
                    .getCostStrVersion().getTeesc01Coststruct(), form
                    .getVehicleLine(), form.getMix()).getMacropartInfo());
        } catch (FullEconomicsException e) {
            ActionMessages am = new ActionMessages();
            am.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(e
                    .getMessageResource()));
            saveErrors(request, am);
        }

        return mapping.findForward("success");
    }
}
